import 'package:dio/dio.dart';

// get 请求

class Api {
  static BaseOptions options = BaseOptions(
    baseUrl: "http://101.43.216.253:3000", // host
    connectTimeout: 5000, // 超时
    receiveTimeout: 3000,
  );
  static Dio dio = Dio(options);
  static Future get(String path, Map params, {bool setCookie = false}) async {
    path += '?';
    params.forEach((key, value) {
      path += "$key=$value";
    });
    print(path);
    var result = await dio.get("http://101.43.216.253:3000$path");
    return result.data;
  }

  static loginByphone(params) {
    // 手机号登录
    return get('/login/cellphone', params, setCookie: false);
  }

  static sendCode(params) {
    // 发送验证码
    return get('/captcha/sent', params, setCookie: false);
  }

  static checkCode(params) {
    // 检查验证码
    return get('/captcha/verify', params, setCookie: false);
  }

  static checkPhone(params) {
    // 检查电话号码是否已注册
    return get('/cellphone/existence/check', params);
  }

  static regist(params) {
    // 注册
    return get('/register/cellphone', params);
  }

  static getUserInfo(params) {
    // 获取用户信息
    return get('/user/detail', params);
  }

  static getLikeList(params) {
    // 获取喜欢音乐列表
    return get('/likelist', params);
  }

  static getSongs(params) {
    // 获取歌曲详情
    return get('/song/detail', params);
  }

  static getSongsUrl(params) {
    // 获取歌曲Url ?id=33894312 /song/url?id=405998841,33894312
    return get('/song/url', params);
  }

  static logout(params) {
    return get('/logout', params);
  } // 退出登录

  static getBanner(params) {
    // 获取轮播
    return get('/banner?type=2', params);
  }

  static checkMusic(params) {
    // 音乐是否可用
    return get('/check/music', params);
  }

  static search(params) {
    // 搜索
    return get('/search', params);
  }

  static cloudsearch(params) {
    // 云搜索
    return get('/cloudsearch', params);
  }

  static getrecommendSongs(params) {
    // 每日推荐
    return get('/recommend/songs', params);
  }

  static getLyric(params) {
    // 歌词
    return get('/lyric', params);
  }

  static likeMusic(params) {
    // 喜欢、不喜欢音乐
    return get('/like', params);
  }

  static suggest(params) {
    // 搜索建议
    return get('/search/suggest?type=mobile', params);
  }

  static heartbeatSongs(params) {
    // 心动模式
    return get('/playmode/intelligence/list', params);
  }

  static getComments(params) {
    // 获取评论
    return get('/comment/music', params);
  }
}
